package com.zuiacsn.practice;

import java.util.Arrays;

public class demo01 {
    /**
     * 三个数的最大乘积
     * @param A int整型一维数组
     * @return long长整型
     */
    public long solve (int[] A) {
        if(A == null ||A.length <3){
            return 0;
        }
        Arrays.sort(A);
        int k = A.length-1;
        long l = 0L;
        if(A[k] < 0){
            // 强转为long 要不然会出现负数
            l = (long)A[0]*A[1]*A[2];
            return l;
        }else if(A[k] > 0){
            if(A[k-1]*A[k-2] > A[0]*A[1]){
                l =(long) A[k]*A[k-1]*A[k-2];
                return l;
            }else{
                l = (long)A[k]*A[0]*A[1];
                return l;
            }
        }else{
            return 0;
        }
    }
}
